﻿<%@ Page Title="User Profile" Language="C#" MasterPageFile="~/eTransmittal.Master" AutoEventWireup="true" CodeBehind="Profile.aspx.cs" Inherits="POI.eTransmittal.WebApp.Profile" %>
<%@ Register assembly="DevExpress.Web.v11.2, Version=11.2.7.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" namespace="DevExpress.Web.ASPxSplitter" tagprefix="dx" %>
<%@ Register assembly="DevExpress.Web.ASPxGridView.v11.2, Version=11.2.7.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" namespace="DevExpress.Web.ASPxGridView" tagprefix="dx" %>
<%@ Register assembly="DevExpress.Web.ASPxEditors.v11.2, Version=11.2.7.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" namespace="DevExpress.Web.ASPxEditors" tagprefix="dx" %>
<%@ Register assembly="DevExpress.Xpo.v11.2.Web, Version=11.2.7.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" namespace="DevExpress.Xpo" tagprefix="dx" %>
<%@ Register assembly="DevExpress.Web.v11.2, Version=11.2.7.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" namespace="DevExpress.Web.ASPxPopupControl" tagprefix="dx" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContentPlaceHolder" runat="server">
    <dx:XpoDataSource ID="xpodsTransmittalUser" runat="server" 
        TypeName="POI.eTransmittal.Enitity.User">
    </dx:XpoDataSource>
                        <dx:XpoDataSource runat="server" 
        TypeName="POI.eTransmittal.Enitity.Role" ID="xpodsRoles"></dx:XpoDataSource>

                        <table style="width:100%;">
                            <tr>
                                <td align="center">

                        <dx:ASPxGridView runat="server" ClientInstanceName="grdRoles" KeyFieldName="ID" 
                                        PreviewFieldName="AccessRights" AutoGenerateColumns="False" 
                                        DataSourceID="xpodsRoles" Width="100%" ID="grdRoles" 
                                        onrowdeleted="grdRoles_RowDeleted" onrowinserted="grdRoles_RowInserted" 
                                        onrowupdated="grdRoles_RowUpdated"><Columns>
<dx:GridViewDataTextColumn FieldName="RoleName" VisibleIndex="1" Width="250px">
    <PropertiesTextEdit Width="200px">
    </PropertiesTextEdit>
    <CellStyle HorizontalAlign="Left">
    </CellStyle>
                                </dx:GridViewDataTextColumn>
<dx:GridViewCommandColumn Width="150px" VisibleIndex="4">
<EditButton Visible="True"></EditButton>

<NewButton Visible="True"></NewButton>

<DeleteButton Visible="True"></DeleteButton>

<UpdateButton Visible="True"></UpdateButton>

<ClearFilterButton Visible="True"></ClearFilterButton>
    <CellStyle HorizontalAlign="Center">
    </CellStyle>
</dx:GridViewCommandColumn>
                                <dx:GridViewDataButtonEditColumn FieldName="AccessRights" VisibleIndex="2">
                                    <PropertiesButtonEdit ClientInstanceName="txtColumnAccessRights">
                                        <ClientSideEvents ButtonClick="function(s, e) {
	popupSelectAccessRights.ShowAtElement(s.GetMainElement());
}" />
                                        <Buttons>
                                            <dx:EditButton Text="...">
                                            </dx:EditButton>
                                        </Buttons>
                                    </PropertiesButtonEdit>
                                    <CellStyle HorizontalAlign="Left">
                                    </CellStyle>
                                </dx:GridViewDataButtonEditColumn>
</Columns>

                            <SettingsEditing EditFormColumnCount="1" />
                            <SettingsDetail AllowOnlyOneMasterRowExpanded="True" ShowDetailRow="True" />

<Templates>
    <DetailRow>
        <dx:ASPxGridView ID="grdUsers" runat="server" AutoGenerateColumns="False" 
            ClientInstanceName="grdUsers" DataSourceID="xpodsTransmittalUser" 
            KeyFieldName="UserID" 
            onbeforeperformdataselect="grdUsers_BeforePerformDataSelect" 
            oninitnewrow="grdUsers_InitNewRow" Width="100%" 
            oncustomcallback="grdUsers_CustomCallback" 
            onrowdeleted="grdUsers_RowDeleted">
            <ClientSideEvents CustomButtonClick="function(s, e) 
{	
	if (e.buttonID == 'btnGrdUserAdd')
	{
		popupUserList.ShowAtElement(s.GetMainElement());
	}
	else
	{
		s.DeleteRow(e.visibleIndex);
	}
}" />
            <Columns>
                <dx:GridViewDataTextColumn FieldName="UserID" ReadOnly="True" VisibleIndex="0" 
                    Width="150px">
                    <CellStyle HorizontalAlign="Left">
                    </CellStyle>
                </dx:GridViewDataTextColumn>
                <dx:GridViewDataTextColumn Caption="User Name" FieldName="PremierOilUser.Name" 
                    VisibleIndex="1">
                    <CellStyle HorizontalAlign="Left">
                    </CellStyle>
                </dx:GridViewDataTextColumn>
                <dx:GridViewCommandColumn VisibleIndex="2" Width="100px">
                    <ClearFilterButton Visible="True">
                    </ClearFilterButton>
                    <CustomButtons>
                        <dx:GridViewCommandColumnCustomButton ID="btnGrdUserAdd" Text="Add">
                        </dx:GridViewCommandColumnCustomButton>
                        <dx:GridViewCommandColumnCustomButton ID="btnGrdUserRemove" Text="Remove">
                        </dx:GridViewCommandColumnCustomButton>
                    </CustomButtons>
                </dx:GridViewCommandColumn>
            </Columns>
            <Templates>
                <EmptyDataRow>
                    <dx:ASPxHyperLink ID="hypAddUser" runat="server" 
                        ClientInstanceName="hypAddUser" NavigateUrl="#" Text="Add">
                        <ClientSideEvents Click="function(s, e) {
	popupUserList.ShowAtElement(grdUsers.GetMainElement());
}" />
                    </dx:ASPxHyperLink>
                </EmptyDataRow>
            </Templates>
        </dx:ASPxGridView>
    </DetailRow>
    <PreviewRow>
                                    <table style="width:100%;" border="1" cellspacing="0">
                                        <tr>
                                            <td>
                                                <%# Eval("AccessRights") %></td>
                                            <td align="right" width="100px">
                                                <dx:ASPxHyperLink ID="hypEditAccessRights" runat="server" 
                                                    ClientInstanceName="hypEditAccessRights" NavigateUrl="#" 
                                                    Text="Edit Access Rights" />
                                            </td>
                                        </tr>
                                    </table>
                                
</PreviewRow>
</Templates>
</dx:ASPxGridView>

                                    <dx:ASPxPopupControl ID="popupSelectAccessRights" runat="server" 
                                        ClientInstanceName="popupSelectAccessRights" HeaderText="Select Access Rights" 
                                        PopupHorizontalAlign="RightSides" PopupVerticalAlign="Below" Width="300px" 
                                        AllowDragging="True">
                                        <ClientSideEvents Shown="function(s, e) 
{
    grdAccessRights.UnselectRows();

	accessRights = txtColumnAccessRights.GetText();
	var indices = new Array();
	index = 0;
	for (i = 0; i &lt; grdAccessRights.GetVisibleRowsOnPage(); i++)
	{
		key = grdAccessRights.GetRowKey(i);

		if	(accessRights.indexOf(key) != -1)
		{			
			//grdAccessRights.SelectRows(i);
			indices[index] = i;			
            index++;
		}		
	}
	
	if (indices.length &gt; 0)
		grdAccessRights.SelectRows(indices);
}" />
                                        <ContentCollection>
<dx:PopupControlContentControl runat="server" SupportsDisabledAttribute="True">
    <table style="width:100%;">
        <tr>
            <td>
                <dx:ASPxGridView ID="grdAccessRights" runat="server" 
                    AutoGenerateColumns="False" ClientInstanceName="grdAccessRights" 
                    KeyFieldName="AccessRight" Width="100%">
                    <Columns>
                        <dx:GridViewCommandColumn ShowInCustomizationForm="True" 
                            ShowSelectCheckbox="True" VisibleIndex="0">
                            <ClearFilterButton Visible="True">
                            </ClearFilterButton>
                        </dx:GridViewCommandColumn>
                        <dx:GridViewDataTextColumn Caption="Access Rights" FieldName="AccessRight" 
                            ShowInCustomizationForm="True" VisibleIndex="1">
                            <CellStyle HorizontalAlign="Left">
                            </CellStyle>
                        </dx:GridViewDataTextColumn>
                    </Columns>
                </dx:ASPxGridView>
            </td>
        </tr>
        <tr>
            <td>
                <dx:ASPxButton ID="btnPopupOk" runat="server" AutoPostBack="False" Text="Ok" 
                    Width="100%">
                    <ClientSideEvents Click="function(s, e) 
{
	accessRights = '';
	for (i = 0; i &lt; grdAccessRights.GetVisibleRowsOnPage(); i++)
	{
		if (grdAccessRights.IsRowSelectedOnPage(i))
		{
			if (accessRights != '')
				accessRights += ', ';
			
			accessRights += grdAccessRights.GetRowKey(i);
		}		
	}

	txtColumnAccessRights.SetText(accessRights);

	popupSelectAccessRights.Hide();

	grdAccessRights.UnselectRows();
}" />
                </dx:ASPxButton>
            </td>
        </tr>
    </table>
                                            </dx:PopupControlContentControl>
</ContentCollection>
                                    </dx:ASPxPopupControl>
                                    <dx:ASPxPopupControl ID="popupUserList" runat="server" 
                                        ClientInstanceName="popupUserList" HeaderText="Select User" 
                                        PopupHorizontalAlign="RightSides" PopupVerticalAlign="Below" Width="300px" 
                                        AllowDragging="True" RenderMode="Lightweight">
                                        <ContentCollection>
<dx:PopupControlContentControl runat="server" SupportsDisabledAttribute="True">
    <table style="width:100%;">
        <tr>
            <td>
                <dx:XpoDataSource ID="xpodsUserList" runat="server" 
                    TypeName="POI.eTransmittal.Enitity.TransmittalUser">
                </dx:XpoDataSource>
                <dx:ASPxGridView ID="grdUserList" runat="server" AutoGenerateColumns="False" 
                    ClientInstanceName="grdUserList" DataSourceID="xpodsUserList" 
                    KeyFieldName="UserID" Width="100%">
                    <Columns>
                        <dx:GridViewCommandColumn ShowInCustomizationForm="True" 
                            ShowSelectCheckbox="True" VisibleIndex="0" Width="50px">
                            <ClearFilterButton Visible="True">
                            </ClearFilterButton>
                        </dx:GridViewCommandColumn>
                        <dx:GridViewDataTextColumn FieldName="Name" ShowInCustomizationForm="True" 
                            VisibleIndex="2">
                            <Settings AutoFilterCondition="Contains" />
                            <CellStyle HorizontalAlign="Left">
                            </CellStyle>
                        </dx:GridViewDataTextColumn>
                    </Columns>
                    <SettingsPager NumericButtonCount="1" PageSize="5">
                    </SettingsPager>
                    <Settings ShowFilterRow="True" />
                </dx:ASPxGridView>
            </td>
        </tr>
        <tr>
            <td>
                <dx:ASPxButton ID="btnSelectUserOk" runat="server" AutoPostBack="False" 
                    ClientInstanceName="btnSelectUserOk" Text="Ok" Width="100%">
                    <ClientSideEvents Click="function(s, e) 
{
    grdUserList.GetSelectedFieldValues('UserID', onGetSelectedUserList);

	popupUserList.Hide();
}" />
                </dx:ASPxButton>
                <dx:ASPxTextBox ID="txtUserListSelectedValues" runat="server" 
                    ClientInstanceName="txtUserListSelectedValues" ClientVisible="False" 
                    Width="170px">
                </dx:ASPxTextBox>
            </td>
        </tr>
    </table>
                                            </dx:PopupControlContentControl>
</ContentCollection>
                                    </dx:ASPxPopupControl>
                                </td>
                            </tr>
    </table>
<script language="javascript">
        function onGetSelectedUserList(selectedValues)
        {
            txtUserListSelectedValues.SetText(selectedValues);

            grdUsers.PerformCallback();

            
        }
</script>

</asp:Content>

